package com.tpo.jnotes.loader.view;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Rectangle;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JLayeredPane;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import javax.swing.border.LineBorder;

import com.tpo.jnotes.base.colors.BColors;
import com.tpo.jnotes.base.resource.BResConstants;
import com.tpo.jnotes.base.resource.BResource;
import com.tpo.jnotes.loader.lib.dialogs.LProgressBar;

public class LMainSplashScreen extends JFrame
{

    private final JLayeredPane layeredPane;
    private final JLabel statusLabel;
    private final LProgressBar progressBar;
    private final JLabel versionLabel;

    public void setVersion( String version )
    {
        if( version == null )
            version = "0.0";
        versionLabel.setText( version );
    }

    public LMainSplashScreen()
    {
        setPreferredSize( new Dimension( 298, 136 ) );
        setIconImage( BResource.getImage( "/icon/notes-icon.png" ) );
        setAlwaysOnTop( true );
        setFocusableWindowState( false );
        setEnabled( false );
        setResizable( false );
        setUndecorated( true );
        getContentPane().setLayout( new BorderLayout( 0, 0 ) );

        layeredPane = new JLayeredPane();
        layeredPane.setBorder( new LineBorder( Color.WHITE ) );
        layeredPane.setBounds( new Rectangle( 0, 0, 400, 300 ) );
        getContentPane().add( layeredPane, BorderLayout.CENTER );

        versionLabel = new JLabel( "0.0" );
        versionLabel.setForeground( Color.WHITE );
        versionLabel.setFont( new Font( "Tahoma", Font.PLAIN, 11 ) );
        versionLabel.setBounds( 282, 0, 16, 26 );
        layeredPane.add( versionLabel );

        JPanel panel = new JPanel();
        panel.setOpaque( false );
        panel.setBounds( 0, 91, 298, 45 );
        layeredPane.add( panel );
        panel.setLayout( new BorderLayout( 0, 0 ) );

        statusLabel = new JLabel( "Checking for updates ..." );
        statusLabel.setFont( new Font( "Tahoma", Font.PLAIN, 11 ) );
        panel.add( statusLabel, BorderLayout.CENTER );
        statusLabel.setHorizontalAlignment( SwingConstants.CENTER );
        statusLabel.setForeground( BColors.WHITE_D );

        progressBar = new LProgressBar();
        progressBar.setBorder( new LineBorder( Color.WHITE ) );
        panel.add( progressBar, BorderLayout.SOUTH );

        JLabel LabelPicture = new JLabel( "" );
        LabelPicture.setBounds( new Rectangle( 0, 0, 298, 136 ) );
        layeredPane.add( LabelPicture, BorderLayout.NORTH );
        LabelPicture.setIconTextGap( 0 );
        LabelPicture.setIcon( BResource.getIcon( BResConstants.SPLASH_IMG ) );
    }

    public void setStatus( String text )
    {
        statusLabel.setText( text );
    }

    public LProgressBar getProgressBar()
    {
        return progressBar;
    }

}
